﻿using Lamex.Base;
using Lamex.Library.CommonClass;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mIE.Calculate
{
   public class Again_Cal_WorkHours
    {
        public static double Get_Cal_WorkHours(DataTable dtFeature_Values, DataTable dtFeature_Def, string StrDWG_No, string StrPart_No, string StrFeature_Name, string StrPROCESS_CODE, string StrFeature_Values)
        {
            double strValue_1 = 0, strLabor_Value = 0;
            //跟进特征名称查出值逻辑【需要再次查询，因为该方法多个地方用到，不能作为参数】
            string VALUE_LOGIC = "";
            DataRow[] dr1 = dtFeature_Def.Select("FEATURE_NAME='" + StrFeature_Name + "'");
            if (dr1.Length > 0)
            {
                VALUE_LOGIC = dr1.CopyToDataTable().Rows[0]["VALUE_LOGIC"].ToString();
            }
            //特征针对电车车缝计算V值
            if (StrFeature_Name == "S02_电车车缝")
            {
                double temp = 0;
                DataTable dtTemp = Calculate.LGC_VAL_S02_S03.GetSeat_Value(StrPart_No, StrFeature_Name, out temp);
                strValue_1 = temp;
            }
            if (VALUE_LOGIC == "LGC_VAL_T01_BUMPING")//(StrFeature_Name == "T01_数冲凸包")
            {
                double temp = 0;
                temp = Calculate.LGC_VAL_T01_BUMPING.LGC_VAL_T01_BUMPING_VALUE(StrDWG_No, StrPart_No, StrFeature_Values);
                StrFeature_Values = temp.ToString();
            }
            if (VALUE_LOGIC == "LGC_VAL_T03_WELDING")//(StrFeature_Name == "T03_焊接点数")
            {
                double temp = 0;
                temp = Calculate.LGC_VAL_T03_WELDING.LGC_VAL_T03_WELDING_VALUE(StrDWG_No, StrPart_No, StrFeature_Values);
                StrFeature_Values = temp.ToString();
            }
          
            //转换特征值
            if (StrFeature_Values.Contains("?"))
            {
                if (Common.GetFeat_Value.IsNumber(IELogicHelper.GetLogicValue(StrDWG_No, StrPart_No, StrFeature_Values)))
                    strValue_1 = Convert.ToDouble(IELogicHelper.GetLogicValue(StrDWG_No, StrPart_No, StrFeature_Values));
            }
            else if (StrFeature_Values == "LGC_VAL_T01_BUMPING")
            {
                strValue_1 = Calculate.LGC_VAL_T01_BUMPING.LGC_VAL_T01_BUMPING_VALUE(StrDWG_No, StrPart_No, StrFeature_Name);
            }
            else if (StrFeature_Values == "LGC_VAL_T03_WELDING")
            {
                strValue_1 = Calculate.LGC_VAL_T03_WELDING.LGC_VAL_T03_WELDING_VALUE(StrDWG_No, StrPart_No, StrFeature_Name);
            }
            else
            {
                if (Common.GetFeat_Value.IsNumber(StrFeature_Values))
                    strValue_1 = Convert.ToDouble(StrFeature_Values);

            }
            #region 当特征值为0时，工时为0
            if (strValue_1 == 0 && (StrFeature_Values.Trim().Length <= 0 || StrFeature_Values.Trim() == "0"))
                strLabor_Value = 0;
            #endregion
            else
            {
                DataTable dtFeature = BaseBuildSql.GetDataTableBySql(" select * from IE_Feature_Definatian where 1=1 and FEATURE_NAME = '" + StrFeature_Name + "'");
                if (dtFeature.Rows.Count != 0)
                {
                    if (dtFeature.Rows[0][0] != null)
                    {
                        string strValues = dtFeature.Rows[0]["WORKTIME_LOGIC_CODE"].ToString();
                        if (strValues.Contains("?"))
                            strLabor_Value = Math.Round(Convert.ToDouble(IELogicHelper.GetLogicValue(StrDWG_No, StrPart_No, StrFeature_Values.Trim())), 2);
                        else if (strValues == "LGC_TIM_LABOR")
                            strLabor_Value = Math.Round(LGC_TIM_LABOR.LGC_TIM_LABOR_VALUE(StrFeature_Name, StrFeature_Values), 2);
                        else if (strValues == "LGC_TIM_T02_BENDING")
                            strLabor_Value = Math.Round(LGC_TIM_T02_BENDING.LGC_TIM_T02_BENDING_VALUE(StrDWG_No, StrPart_No, StrFeature_Values), 2);
                        else if (strValues == "LGC_TIM_VTA")
                            strLabor_Value = Math.Round(LGC_TIM_VTA.LGC_TIM_VTA_VALUE(StrDWG_No, StrPart_No, StrFeature_Name, StrFeature_Values, strValue_1), 2);
                        else if (strValues == "LGC_TIM_D28_SAW")
                            strLabor_Value = Math.Round(LGC_TIM_D28_SAW.LGC_TIM_D28_SAW_VALUE(StrDWG_No, StrPart_No, StrFeature_Values), 2);
                        else if (strValues == "LGC_TIM_D29_SAW")
                            strLabor_Value = Math.Round(LGC_TIM_D29_SAW.LGC_TIM_D29_SAW_VALUE(StrDWG_No, StrPart_No, StrFeature_Values), 2);
                        else if (strValues == "LGC_TIM_D31_SAW")
                            strLabor_Value = Math.Round(LGC_TIM_D31_SAW.LGC_TIM_D31_SAW_VALUE(StrDWG_No, StrPart_No, StrFeature_Values), 2);
                        //else if (strValues == "LGC_TIM_D42_SAW")
                        //    strLabor_Value = Math.Round(LGC_TIM_D42_SAW.LGC_TIM_D42_SAW_VALUES(dtFeature_Values), 2);
                        else
                            strLabor_Value = 0;
                    }
                }
            }
            return strLabor_Value;
        }
    }
}
